<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of AttachmentImpl
 *
 * @author Administrator
 */

namespace frontend\dao\impl;

use frontend\bean\Attachment;
use frontend\dao\AttachmentDao;
use Yii;

class AttachmentDaoImpl implements AttachmentDao {



    public function addAttachment(Attachment $attach) {
        $connection = Yii::$app->db;
        $sql = "INSERT INTO  `attachment`  (uid,type,fname,`key`,create_time,description)"
                . "                                 VALUES (:uid,:type,:fname,:key,:create_time,:description)";
        $command = $connection->createCommand($sql);
        $command->bindValue(":uid", $attach->getUid());
        $command->bindValue(":type", $attach->getType());
        $command->bindValue(":fname", $attach->getFname());
        $command->bindValue(":key", $attach->getKey());
        $command->bindValue(":create_time", $attach->getCreate_time());
        $command->bindValue(":description", $attach->getDescription());
        $command->execute();
        return true;
    }
    public function getAttachmentInfo($aid){
          $connection = Yii::$app->db;
        $sql = "SELECT * FROM `attachment` WHERE aid=:aid ";
        $command = $connection->createCommand($sql);
        $command->bindValue(':aid', $aid);
        $result = $command->queryOne();

        return $result ? (new Attachment())->load($result) : null;
    }

    public function getNewId() {
        return Yii::$app->db->getLastInsertID();
    }

//put your code here
}
